home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / turboscr.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  8KB  |  423 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <conio.h>
  7. #include <signal.h>
  8. #include <float.h>
  9.  
  10. #ifndef EMXOS2                  /* a.r. */
  11.    #include <bios.h>
  12. #else
  13.    #include <sys/video.h>
  14.    #include <sys/winmgr.h>
  15.    #define textattr v_attrib
  16.    int vx_top = 1, vx_bot = 25;
  17. #endif
  18.  
  19. #define false 0
  20. #define true (!false)
  21.  
  22.  
  23. #ifndef EMXOS2                  /* a.r. */
  24.    #define BCOLOR BLUE
  25.    #define FCOLOR MAGENTA
  26.    #define HBCOLOR h_bcolor
  27.    #define HVCOLOR h_fcolor
  28.    #define VCOLOR WHITE
  29. #else
  30.  
  31. enum COLORS {
  32.         BLACK,
  33.         BLUE,
  34.         GREEN,
  35.         CYAN,
  36.         RED,
  37.         MAGENTA,
  38.         BROWN,
  39.         LIGHTGRAY,
  40.         DARKGRAY,
  41.         LIGHTBLUE,
  42.         LIGHTGREEN,
  43.         LIGHTCYAN,
  44.         LIGHTRED,
  45.         LIGHTMAGENTA,
  46.         YELLOW,
  47.         WHITE
  48. };
  49.  
  50. #define BCOLOR B_BLUE
  51. #define FCOLOR F_MAGENTA
  52. #define HBCOLOR h_bcolor
  53. #define HVCOLOR h_fcolor
  54. #define VCOLOR B_WHITE
  55.  
  56. void insline(void)
  57. {
  58.     v_insline(1);
  59. }
  60. void delline(void)
  61. {
  62.     v_delline(1);
  63. }
  64.  
  65. clrscr(void)
  66. {
  67. /*        printf("\033[2J\033[H");*/
  68.     v_clear();
  69. }
  70. void normvideo(void)
  71. {
  72.     printf("\033[0m");
  73. }
  74. void highvideo(void)
  75. {
  76.     printf("\033[1m");
  77. }
  78. void lowvideo(void)
  79. {
  80.     printf("\033[0m");
  81. }
  82. void textbackground( unsigned char BgColor )
  83. {   
  84.     if (BgColor > 7) return;
  85.     if      (BgColor == 6) BgColor = 3;            
  86.     else if (BgColor == 3) BgColor = 6;
  87.     else if (BgColor == 4) BgColor = 1;
  88.     else if (BgColor == 1) BgColor = 4;
  89.     printf("\033[%dm", BgColor + 40);
  90. }
  91.  
  92. void textcolor( unsigned char FgColor )
  93. {
  94.     unsigned short *ScrAttr;
  95.     ScrAttr=(unsigned short *) malloc(sizeof(unsigned short));
  96.     *ScrAttr=0;
  97.     if (FgColor > 128)
  98.             {
  99.         printf("\033[5m"); /* blink  */
  100.         FgColor -= 128;
  101.         }
  102.     if ( FgColor > 7 && FgColor < 16)
  103.             {
  104.              *ScrAttr = 1;
  105.              FgColor -= 8;
  106.             }
  107.         if      (FgColor == 6) FgColor = 3;            
  108.         else if (FgColor == 3) FgColor = 6;
  109.         else if (FgColor == 4) FgColor = 1;
  110.             else if (FgColor == 1) FgColor = 4;
  111.            printf("\033[%d;%dm", *ScrAttr, FgColor + 30);
  112.            free(ScrAttr);
  113. }
  114.  
  115. void gotoxy( int x, int y)
  116. {
  117.     v_gotoxy( x-1, y+vx_top-2 );
  118. }
  119. int wherex(void)
  120. {
  121.     int x, y;
  122.     v_getxy(&x, &y);
  123.     return x+1;
  124. }
  125. int wherey(void)
  126. {
  127.     int x, y;
  128.     v_getxy(&x, &y);
  129.     return y + 1;
  130. }
  131.  
  132. struct text_info
  133.        {
  134.         unsigned int winleft,   wintop;
  135.         unsigned int winright,  winbottom;
  136.         unsigned int attribute, normattr;
  137.         unsigned int currmode; 
  138.         unsigned int screenheight, screenwidth; 
  139.         unsigned int curx,      cury; 
  140.        };
  141.  
  142. int gettextinfo(struct text_info *r)
  143. {
  144.         r->curx = wherex();
  145.         r->cury = wherey();
  146.         r->winleft = 1;
  147.         r->winright = 80;
  148.         r->wintop = vx_top;
  149.         r->winbottom = vx_bot;
  150.         r->attribute = v_getattr();
  151. }
  152. int gettext( int left, int top, int right, int bottom, void *destin)
  153. {
  154.  unsigned int length;
  155.  
  156.  length = 80 * (bottom - top + 1) * 2;
  157.  VioReadCellStr( destin, &length, top-1, left-1, 0);
  158. }
  159. int puttext(int left, int top, int right, int bottom, void *source)
  160. {
  161.  unsigned int length;
  162.  
  163.  length = 80 * (bottom - top + 1) * 2;
  164.  VioWrtCellStr(  source, &length, top-1, left-1, 0);
  165. }
  166. void window(int left, int top, int right, int bottom)
  167. {
  168.     vx_top = top;
  169.     vx_bot = bottom;
  170. }
  171. #endif /* EMXOS2 */
  172.  
  173. extern int h_bcolor;
  174. extern int h_fcolor;
  175. extern int noscreenio;
  176.  
  177. int gle_abort(char *s);
  178. int graphmode(void);
  179. int hpgl_initstr(void);
  180.  
  181. scr_refresh()
  182. {
  183. }
  184. int scr_getch()
  185. {
  186. }
  187. void exitcode(int i,int j);
  188. void exitcode_c(int i,int j);
  189. void exitcodef(int i,int j);
  190. scr_init()
  191. {
  192.     signal(SIGFPE,exitcodef);
  193. #ifndef DJ                                /* a.r. */
  194.     signal(SIGABRT,exitcode);
  195. #endif
  196.     signal(SIGILL,exitcode);
  197.     signal(SIGINT,exitcode_c);
  198.     signal(SIGSEGV,exitcode);
  199. #ifndef EMXOS2
  200.     signal(SIGTERM,exitcode);
  201. #endif        
  202. #ifdef EMXOS2                           /* a.r. */
  203.     v_init();
  204.     v_attrib(F_YELLOW | B_BLUE | INTENSITY);
  205. #endif
  206. }
  207. int d_tidyup(void);
  208.  
  209. #if (defined MANIP || defined SURFACE)
  210.     /* nothing */
  211. #else
  212. extern int abort_flag;
  213. #endif
  214. void exitcode_c(int i, int j)
  215. {
  216.     static char etxt[60];
  217.     printf("Abort key\n");
  218. #if (defined MANIP || defined SURFACE)
  219.     /* nothing */
  220. #else
  221.     abort_flag = true;
  222. #endif
  223.     signal(SIGINT,exitcode_c);
  224. }
  225. abort_key(void)
  226. {
  227. #ifndef EMXOS2                          /* a.r. */
  228.     int c;
  229.  #if (defined MANIP || defined SURFACE)
  230.     /* nothing */
  231.  #else
  232.     if (abort_flag) return true;
  233.  #endif
  234.     if (kbhit()) {
  235.         c = bioskey(1);
  236.         c = c & 0xff;
  237.         if (c==27) 
  238.                {
  239.             getch();
  240.                #if (defined MANIP || defined SURFACE)
  241.             /* nothing */
  242.                #else
  243.             abort_flag = true;
  244.                #endif
  245.             return true;
  246.                }
  247.     }
  248. #else
  249.     #ifndef MANIP
  250.     peekMsg();
  251.     #endif
  252. #endif
  253.     return false;
  254. }
  255.  
  256. void exitcode(int i, int j)
  257. {
  258.     static char etxt[60];
  259.     d_tidyup();
  260.     sprintf(etxt,"Exit handler called %d %d \n",i,j);
  261.     gle_abort(etxt);
  262. }
  263. void exitcodef(int i, int j)
  264. {
  265.     d_tidyup();
  266.     printf("Floating point error %d %d \n",i,j);
  267. #if ( ! ( defined DJ  ||  defined EMXOS2 ))                   /* a.r. */
  268.     if (j==FPE_ZERODIVIDE) gle_abort("Divide by zero \n");
  269.     if (j==FPE_INTDIV0) gle_abort("Interger Divide by zero \n");
  270.     if (j==FPE_OVERFLOW) gle_abort("Numeric overflow \n");
  271. #endif
  272.     gle_abort("Floating point Exit handler called");
  273. }
  274. scr_end()
  275. {
  276. #ifdef DJ                                       /* a.r. */
  277.     normvideo();
  278.     ScreenClear();
  279. #elif EMXOS2                                    /* a.r. */
  280.     normvideo();
  281.     v_attrib(F_WHITE | B_BLACK);
  282.     clrscr();
  283. #else
  284. #endif
  285. }
  286. struct text_info r;
  287. void *screensave;
  288. screen_save()
  289. {
  290.     if (noscreenio) return;
  291.     gettextinfo(&r);
  292.     screensave = malloc(25*80*2);
  293.     if (screensave==NULL) return;
  294.     gettext(1,1,80,25,screensave);
  295. }
  296. screen_restore()
  297. {
  298.     if (noscreenio) return;
  299.     if (screensave==NULL) return;
  300.     puttext(1,1,80,25,screensave);
  301.     free(screensave);
  302.     screensave = NULL;
  303.     textattr(r.attribute);
  304.     window(r.winleft,r.wintop,r.winright,r.winbottom);
  305.     gotoxy(r.curx,r.cury);
  306. }
  307. scr_savexy()
  308. {
  309.     if (noscreenio) return;
  310.     gettextinfo(&r);
  311. }
  312. scr_left(int i)
  313. {
  314.     if (noscreenio) return;
  315.     gotoxy(wherex()-i,wherey());
  316. }
  317. scr_right(int i)
  318. {
  319.     if (noscreenio) return;
  320.     gotoxy(wherex()+i,wherey());
  321. }
  322. scr_restorexy()
  323. {
  324.     if (noscreenio) return;
  325.     textattr(r.attribute);
  326. #if (defined EMXOS2 && defined MANIP)
  327.  
  328. #else
  329.     window(r.winleft,r.wintop,r.winright,r.winbottom);
  330. #endif
  331.     gotoxy(r.curx,r.cury);
  332. }
  333. scr_gets(char *x)
  334. {
  335.     gets(x);
  336. }
  337.  
  338. extern int scr_blackwhite;
  339. scr_norm()  /* yellow on blue */
  340. {
  341.         if (noscreenio) return;
  342. #ifndef EMXOS2                                          /* a.r. */ 
  343.         if (scr_blackwhite) {
  344.                 textcolor(WHITE); textbackground(BLACK);
  345.         } else {
  346.                 textcolor(YELLOW); textbackground(BLUE);
  347.         }
  348. #else
  349.         if (scr_blackwhite) {
  350.                 v_attrib(F_WHITE | B_BLACK | INTENSITY);
  351.         } else {
  352.                 v_attrib(F_YELLOW | B_BLUE |INTENSITY);
  353.                 textbackground(BLUE);
  354.         }        
  355. #endif
  356. }
  357. int scr_grey(void);
  358. scr_menuhi()
  359. {
  360.     if (noscreenio) return;
  361.     scr_grey();
  362. }
  363. scr_menuval()
  364. {
  365.         if (noscreenio) return;
  366. #ifndef EMXOS2                                                  /* a.r. */
  367.         textcolor(WHITE); textbackground(BLUE);
  368. #else
  369.         v_attrib(F_WHITE | B_BLUE | INTENSITY);
  370.         textbackground(BLUE);
  371. #endif
  372. }
  373. scr_menubg()
  374. {
  375.         if (noscreenio) return;
  376. #ifndef EMXOS2                                                  /* a.r. */
  377.         textcolor(YELLOW); textbackground(BLUE);
  378. #else
  379.         v_attrib(F_YELLOW | B_BLUE | INTENSITY);
  380.         textbackground(BLUE);
  381. #endif
  382. }
  383. scr_inv()   /* black on white */
  384. {
  385.         if (noscreenio) return;
  386. #ifndef EMXOS2                                                  /* a.r. */
  387.         textcolor(WHITE); textbackground(BLACK);
  388. #else
  389.         v_attrib(F_WHITE | B_BLACK | INTENSITY);
  390.         textbackground(BLACK);
  391. #endif
  392. }
  393. scr_grey()  /* black on grey */
  394. {
  395.         if (noscreenio) return;
  396. #ifndef EMXOS2                                                  /* a.r. */
  397.         textcolor(BLACK); textbackground(LIGHTGRAY);
  398. #else
  399.         v_attrib(B_WHITE | F_BLACK);
  400.         textbackground(WHITE);
  401. #endif
  402. }
  403. scr_isblackwhite()
  404. {
  405.     char *s;
  406.     s = getenv("CGLE_BLACKWHITE");
  407.     if (s!=NULL) return true;
  408.     else return false;
  409. }
  410. vax_edt(char *s)
  411. {
  412. }
  413. #if ( ! ( defined DJ || defined EMXOS2 ) )                 /* a.r. */
  414. char *getsymbol(char *s)
  415. {
  416.     static char ss[100];
  417.     ss[0] = 0;
  418.     if ( getenv(s) != NULL) strcpy(ss,getenv(s));
  419.     return ss;
  420. }
  421. #endif
  422.  
  423.